package com.tensai.study.基础.设计模式.单例模式;

/**
 * 懒汉式加载 ：时间换空间
 * @author tensai
 */
public class C01_Singleton {

    private static C01_Singleton singleton = null;

    private C01_Singleton() {
    }

    private static C01_Singleton getInstance() {
        //TODO 这里存在线程安全问题
        if (singleton == null) {
            singleton = new C01_Singleton();
        }
        return singleton;
    }

    public static void main(String[] args) {
        C01_Singleton singleton1 = C01_Singleton.getInstance();
        C01_Singleton singleton2 = C01_Singleton.getInstance();
        /*
         * 内存地址一样，说明指向的是同一个对象
         * C01_Singleton@1e579dc
         * C01_Singleton@1e579dc
         */
        System.out.println(singleton1);
        System.out.println(singleton2);
    }

}
